﻿<?php 
//error_reporting(E_ERROR|E_PARSE);
session_start();
if($_SESSION["islogin"]!=='igiveyouthepower'){
echo "<script language=JavaScript>\r\n";
echo "alert('请先登录!');\r\n";
echo "location.href='../index.php'\r\n";
echo "</script>";
}else{
require_once('../config.php');
?>
<?php 
$conn = mysqli_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd,$cfg_dbname);
$action=($_GET["action"]);
$id=intval($_GET["id"]);
$platform=$_GET["platform"];
if($_POST['id']<>''){$ID_Dele=implode(",",$_POST['id']);}
$bname=$_POST["bname"];
$Description=$_POST["Description"];
$Keywords=$_POST["Keywords"];
$user_name=$_SESSION["managername"];
if($action=='add'){
$query="select * from ph_bcategory where bname='".$bname."' and user_name='".$user_name."'";
$result=mysqli_query($conn,$query);
if(mysqli_num_rows($result)>=1){
echo "<script language=JavaScript>\r\n";
echo "alert('该分类已在其他平台创建!');\r\n";
echo "location.href='bigcategory.php?platform=".$platform."'\r\n";
echo "</script>";
}else{
$sql = "INSERT INTO ph_bcategory(bname,user_name,platform)VALUES('".$bname."','".$user_name."','".$platform."')";
mysqli_query($conn,$sql);
echo "<script language=JavaScript>\r\n";
echo "alert('新增成功!');\r\n";
echo "location.href='bigcategory.php?platform=".$platform."'\r\n";
echo "</script>";
}}
if($action=='edit'){

$sql = "update ph_bcategory set bname='".$bname."',Keywords='".$Keywords."',Description='".$Description."' where ID='".$id."'";
mysqli_query($conn,$sql);
echo "<script language=JavaScript>\r\n";
echo "alert('修改成功!');\r\n";
echo "location.href='bigcategory.php?platform=".$platform."'\r\n";
echo "</script>";
}
if($action=='del'){
if($ID_Dele<>''){
$result=mysqli_query($conn,"select * from ph_bcategory where id in(".$ID_Dele.")");
while($row=mysqli_fetch_array($result)){
$results=mysqli_query($conn,"select * from ph_products where bname='".$row["bname"]."'");
while($rows=mysqli_fetch_array($results)){
mysqli_query($conn,"delete from ph_shuxing where proid ='".$rows["ID"]."'");

mysqli_query($conn,"delete from ph_img where id in(select imgid from(select imgid from ph_proimg where proid='".$rows["ID"]."') t)");
mysqli_query($conn,"delete from ph_proimg where proid='".$rows["ID"]."'");
}
mysqli_query($conn,"delete from ph_products where bname ='".$row["bname"]."' and user_name='".$user_name."'");
}
mysqli_query($conn,"delete from ph_bcategory where id in(".$ID_Dele.")");
}
if($id<>''){
$result=mysqli_query($conn,"select * from ph_bcategory where id='".$id."'");
$row=mysqli_fetch_array($result);
$results=mysqli_query($conn,"select * from ph_products where bname='".$row["bname"]."'");
while($rows=mysqli_fetch_array($results)){
mysqli_query($conn,"delete from ph_shuxing where proid ='".$rows["ID"]."'");
mysqli_query($conn,"delete from ph_img where id in(select imgid from(select imgid from ph_proimg where proid='".$rows["ID"]."') t)");
mysqli_query($conn,"delete from ph_proimg where proid='".$rows["ID"]."'");
}
mysqli_query($conn,"delete from ph_products where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_en where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_de where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_fr where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_it where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_es where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_ja where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_th where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_da where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_ky where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_ta where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_nl where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_fa where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_pt where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_ro where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_pl where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_hu where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_no where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_is where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_ne where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_lt where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_bg where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_lo where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_be where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_el where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_vi where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_iw where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_la where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_my where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_ga where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_fi where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_uk where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_mn where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_tl where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_id where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_ar where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_ru where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_hi where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_tr where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_sv where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_ms where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_ca where bname ='".$row["bname"]."' and user_name='".$user_name."'");
mysqli_query($conn,"delete from ph_bcategory where ID ='".$id."'");
}
echo "<script language=JavaScript>\r\n";
echo "alert('删除成功!');\r\n";
echo "location.href='bigcategory.php?platform=".$platform."'\r\n";
echo "</script>";
}
?>
<?php }?>